﻿using Microsoft.AspNetCore.Authorization;
using System.Security.Claims;

namespace Web
{
    public class PolicyAuthorizationHandler : AuthorizationHandler<PermissionRequirement>
    {


        // private readonly ICurrentPrincipalAccessor _principalAccessor;
        private readonly AsyncLocal<ClaimsPrincipal> _currentPrincipal = new AsyncLocal<ClaimsPrincipal>();

        protected override Task HandleRequirementAsync(AuthorizationHandlerContext context, PermissionRequirement requirement)
        {
            // throw new NotImplementedException();

           
            string str = "";
            var role = context.User.FindFirst(c => c.Type == ClaimTypes.Role);
            if (role != null)
            {
                var name = requirement.PermissionName;
                //var roleValue = role.Value;
                //var permissions = RolePermissionCache.GetPermissions(role.Value);
                //if (permissions.Contains(requirement.PermissionName))
                //{
                //    context.Succeed(requirement);
                //}
            }
            //else
            //{
            //    context.Fail();
            //}
            return Task.CompletedTask;
        }

    }
}
